<script lang="ts" setup>
import { useRoute } from 'vue-router';
import { useHead } from '@vueuse/head';
import type { HeadObject } from '@vueuse/head';
import { useRouter } from "vue-router"
import BaseLayout from './base.layout.vue';
import FavoriteButton from '@/components/FavoriteButton.vue';
import type { Tool } from '@/tools/tools.types';

const route = useRoute();
const router = useRouter();
const head = computed<HeadObject>(() => ({
  title: `${route.meta.name} - IT Tools`,
  meta: [
    {
      name: 'description',
      content: route.meta?.description as string,
    },
    {
      name: 'keywords',
      content: ((route.meta.keywords ?? []) as string[]).join(','),
    },
  ],
}));
useHead(head);
const { t } = useI18n();

const goBack = () => {
  router.go(-1)
}

const i18nKey = computed<string>(() => route.path.trim().replace('/', ''));
const toolTitle = computed<string>(() => t(`tools.${i18nKey.value}.title`, String(route.meta.name)));
const toolDescription = computed<string>(() => t(`tools.${i18nKey.value}.description`, String(route.meta.description)));
</script>

<template>
  <div class="tool-layout">

    <div class="tool-header">

      <div flex flex-nowrap items-center justify-between>
        <svg @click="goBack" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 512 512">
          <path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="48"
            d="M244 400L100 256l144-144"></path>
          <path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="48"
            d="M120 256h292"></path>
        </svg>
        <n-h1>
          {{ toolTitle }}
        </n-h1>

        <div>
          <!-- <FavoriteButton :tool="{ name: route.meta.name } as Tool" /> -->
        </div>
      </div>


      <div class="description">
        {{ toolDescription }}
      </div>
    </div>

    <div class="tool-content">
      <slot />
    </div>
  </div>

</template>

<style lang="less" scoped>
.tool-content {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 16px;

  ::v-deep(& > *) {
    flex: 0 1 600px;
  }
}

.tool-layout {
  max-width: 600px;
  margin: 0 auto;
  box-sizing: border-box;

  .tool-header {
    padding: 40px 0;
    width: 100%;
    position: relative;

    svg {
      display: inline-block;
      width: 30px;
      height: 30px;
    }

    .n-h1 {
      display: inline-block;
      opacity: 0.9;
      font-size: 40px;
      font-weight: 400;
      margin: 0;
      line-height: 1;
      margin-left: 10px;
      text-align: right;
    }



    .description {
      margin: 0;
      padding-top: 16px;
      opacity: 0.7;
    }
  }
}
</style>
